/**
 * 
 */
package zkoran.qrfan;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Activity to adding new fan identification to the match
 * 
 * @author zdenda
 *
 */
public class NewFanActivity extends Activity {
	
	private TextView mTextViewName;
	private EditText mEditTextId;
	private Button mButtonOk;
	
	private String mMatchName;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.new_fan);
		
		mEditTextId = (EditText) findViewById(R.id.editText_identification);
		
		mTextViewName = (TextView) findViewById(R.id.textView_match_name);
		
		mMatchName = getIntent().getExtras().getString(MatchActivity.EXTRAS_NAME);
		mTextViewName.setText(mMatchName);
		
		mButtonOk = (Button) findViewById(R.id.button_ok);
		mButtonOk.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				createNewFan();

			}
		});
		
		
	}

	/**
	 * Creates new fan and finishes this activity
	 */
	protected void createNewFan() {
		
		String id = mEditTextId.getText().toString().trim();

		// if name is valid
		if (!id.equals("")) {
			
			if(MatchModel.addfan(mMatchName,id)) {
				Intent intent = new Intent();
				this.setResult(RESULT_OK, intent);
				this.finish();
			}
			
		} else {
			Toast.makeText(this, R.string.message_empty_identification, Toast.LENGTH_LONG).show();
		}
		
		
	}
	
	
	

}
